//
//  DYZChooseInColorController.m
//  DYZCars
//
//  Created by xmy on 16/8/20.
//  Copyright © 2016年 MF. All rights reserved.
//

#import "DYZChooseInColorController.h"
#import "DSHTTPClient.h"
#import "UIColor+Addition.h"
#import "UILabel+Addition.h"
#import "DYZRandomColorController.h"

static NSString *cellId = @"cellId";

@interface DYZChooseInColorController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSArray *dataArray;
@property(nonatomic,strong)UITableView *tableView;

@end

@implementation DYZChooseInColorController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArray = [self loadData];
    
    self.navigationItem.title = @"选择内饰颜色";
    [self setupUI];
    [self addChoose];
     self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    [self leftButton];
}

//左侧返回按钮
- (void)leftButton{
    //左侧返回按钮
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    // 为返回按钮设置图片样式
    [button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    //按钮的点击事件
    [button addTarget:self action:@selector(popController) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = backButton;
    
    //将返回按钮的文字position设置不在屏幕上显示
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
}
//左侧按钮点击事件
- (void)popController{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)setupUI{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain];
    
    [self.view addSubview:tableView];
    
    tableView.dataSource = self;
    tableView.delegate = self;
    
    self.tableView = tableView;
    //注册
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
    
}
//添加自定义view
- (void)addChoose{
    
    UIView *addView = [[UIView alloc]init];    
    addView.userInteractionEnabled = YES;
    
    //背景图片
    UIImageView *backImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more2"]];
    backImage.bounds = addView.frame;
    [addView addSubview:backImage];
    
    UILabel *label = [UILabel labelWithText:@"自定义区域" andTextColor:[UIColor whiteColor] andFontSize:14];
    [label sizeToFit];
    [addView addSubview:label];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow2"]];
    
    [addView addSubview:imageView];
    [imageView sizeToFit];
    
    [self.view addSubview:addView];
    
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGesture:)];
    
    [addView addGestureRecognizer:tap];
    
    [addView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.height.offset(50);
    }];
    [backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(addView);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.bottom.equalTo(addView);
    }];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(addView);
    }];
    
    
}
//手势事件
- (void)tapGesture:(UITapGestureRecognizer *)tap{
    
    DYZRandomColorController *vc = [[DYZRandomColorController alloc]init];
    
    vc.flag = 1;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}


- (NSArray *)loadData{
    
    NSArray *arr = @[@"不限",@"米",@"棕",@"黑",@"红",@"灰",@"蓝"];
    
    return arr;
}
#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
        cell.textLabel.text = self.dataArray[indexPath.row];
    
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    [cell.textLabel setTextColor:[UIColor colorWithHex:0x333333]];
    
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}


@end
